<?php

/*

  Action	$5

  Look through your discard pile, reveal any number of Copper cards from it, and put them into your hand.

 */

class CountingHouse extends Card implements iAction, iKingdom, iProsperity {

    public function __construct() {
        parent::__construct("Counting House", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Look through your discard pile, reveal any number of Copper cards from it, and put them into your hand.");
    }

    public function play(Game $game, $isRealCard) {
        $discardDeck = $game->getDiscardDeck();
        $copper = new Copper();
        $copper_key = $copper->getKey();
        $coppers_found = 0;
        $options = array(new Option(0, 0));
        foreach ($discardDeck as $card) {
            if ($card->getKey() == $copper_key) {
                $coppers_found++;
                $options[] = new Option($coppers_found, $coppers_found);
            }
        }

        if ($coppers_found > 0) {

            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "How many coppers you would like to get from discard?");
            $answer = (int) ($output[0]);
            ScreenDisplay::addScreenMessage($game, true, "put $answer Coppers in your hand", "puts $answer Coppers in his hand");
            for ($i = 0; $i < $answer; $i++) {
                $game->moveCardFromPileToPile("Copper", DiscardPile, PlayHand);
            }
        } else {
            ScreenDisplay::addScreenMessage($game, true, "put 0 Coppers in your hand", "puts 0 Coppers in his hand");
        }

        $game->cardActionFinished();
        return true;
    }

}

?>